<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/29/029
 * Time: 15:36
 */

namespace app\api\controller\v1;

use app\api\controller\BaseController;
use app\api\model\Activity as ActivityModel;
use app\api\validate\LatLngValidate;


class Activity extends BaseController {

    /**
     * 获取最新活动列表
     * @url   activity_new_list
     * @method   get
     * @return array|\think\Paginator
     */
    public function activity_new_list() {
        $where = [
            ['status', 'neq', 1]
        ];

        $list = ActivityModel::getPageListByWhere($where);

        //  如果查询到的数据为空，自定义返回格式，与有数据时保持一致
        if ($list->isEmpty()) {
            $list = [
                'total' => null,
                'per_page' => 15,
                'current_page' => 0,
                'last_page' => null,
                'data' => []
            ];
        }
        return $list;
    }

    /**
     * 获取附近活动列表
     * @url   activity_new_list
     * @method   get
     * @param $lat
     * @param $lng
     * @return array|\PDOStatement|string|\think\Collection
     */
    public function activity_nearby_list($lat, $lng) {
        (new LatLngValidate())->goCheck();
        // 根据用户经纬度 获取附近活动  // 必须是能参与的
        $coord = getAround($lat, $lng, 10000);
        $where = [
            ['lat', 'between', [$coord[0], $coord[1]]],
            ['lng', 'between', [$coord[2], $coord[3]]],
            ['status', '=', 2]
        ];

        $list = ActivityModel::getListByWhere($where);

        //  如果查询到的数据为空，自定义返回格式，与有数据时保持一致
        if ($list->isEmpty()) {
            $list = [
                'total' => null,
                'per_page' => 15,
                'current_page' => 0,
                'last_page' => null,
                'data' => []
            ];
        }
        return $list;
    }


}